package com.btex.app.adapter;

import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.btex.app.MyApplication;
import com.btex.app.R;
import com.btex.app.entity.BiBiListInfo;
import com.btex.app.tools.SharedPreferencesUtil;
import com.btex.app.tools.Tools;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * @author zhangyi<zhangyi, 1104745049@qq.com>
 * @version v1.0
 * @project study1
 * @Description
 * @encoding UTF-8
 * @date 2018/12/27
 * @time 下午3:01
 * @修改记录 <pre>
 * 版本       修改人         修改时间         修改内容描述
 * --------------------------------------------------
 * <p>
 * --------------------------------------------------
 * </pre>
 */


public class BiBiListAdapter extends BaseQuickAdapter<BiBiListInfo.DataBean, BaseViewHolder> {

    public BiBiListAdapter(@Nullable List<BiBiListInfo.DataBean> data) {
        super(R.layout.item_shou_ye_recy, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, BiBiListInfo.DataBean item) {
        SharedPreferencesUtil sharedPreferences = SharedPreferencesUtil.getSharedPreferences(MyApplication.getContextObject());


//        市场
        TextView item_news_type = (TextView) helper.getView(R.id.item_news_type);
//        价格
        TextView item_news_price = (TextView) helper.getView(R.id.item_news_price);
//        涨跌
        TextView item_news_zhang_die = (TextView) helper.getView(R.id.item_news_zhang_die);
//        折合
        TextView item_news_money = (TextView) helper.getView(R.id.item_news_money);

        item_news_money.setVisibility(View.VISIBLE);

        String type = item.getType();
        String danwei = item.getDanwei();
        String pair = item.getPair();
        String change_24h = item.getChange_24h();
        String price_float_num = item.getPrice_float_num();
        String trade_price = item.getTrade_price();
        String rate_price_c = item.getTicker().getRate_price_c();
        String rate_price_u = item.getTicker().getRate_price_u();

        boolean isEngilsh = sharedPreferences.getBoolean("isEngilsh", false);
        if (isEngilsh) {
//            double v = Double.valueOf(rate_price_u) * Double.valueOf(trade_price);
//            String trim = Tools.round(v, Integer.valueOf(price_float_num)).toPlainString().trim();
            item_news_money.setText("$" + rate_price_u);

        } else {
//            double v = Double.valueOf(rate_price_c) * Double.valueOf(trade_price);
//            String trim = Tools.round(v, Integer.valueOf(price_float_num)).toPlainString().trim();

            item_news_money.setText("¥" + rate_price_c);
        }

        if (Double.valueOf(trade_price) == 0) {
            item_news_price.setText("0.00");
        } else {
            String trim1 = Tools.round(Double.valueOf(trade_price), Integer.valueOf(price_float_num)).toPlainString().trim();
            item_news_price.setText(trim1);
        }

        Double change24h = Double.valueOf(change_24h);
        String trim = Tools.round(Double.valueOf(change24h) * 100, 2).toPlainString().trim();

        if (change24h == 0) {
            item_news_zhang_die.setText("+0.00%");
        } else {
            if (change24h < 0) {
                item_news_zhang_die.setText(trim + "%");
            } else {
                item_news_zhang_die.setText("+" + trim + "%");
            }

        }


        if (change24h > 0 || change24h == 0) {

            item_news_zhang_die.setBackgroundResource(R.drawable.item_bg_no);

        } else {
            item_news_zhang_die.setBackgroundResource(R.drawable.item_bg);
        }

        item_news_type.setText(type + "/" + danwei);
    }
}
